﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Safal.IncidentTracker.WebUI.HtmlHelpers
{
    public static class MenuTabHelper
    {
        public static MvcHtmlString MenuTab(this HtmlHelper htmlHelper, IEnumerable<MenuTab> tabs )
        {
            var routeData = htmlHelper.ViewContext.RequestContext.RouteData;
            var controller = routeData.GetRequiredString("controller");
            var action = routeData.GetRequiredString("action");

            TagBuilder ulTag = new TagBuilder("ul");
            foreach (var menuTab in tabs)
            {
                TagBuilder liTag = new TagBuilder("li");
                if (menuTab.Controller.Equals(controller) && menuTab.Action.Equals(action))
                    liTag.AddCssClass("active");
                liTag.InnerHtml = htmlHelper.ActionLink(menuTab.Text, menuTab.Action, menuTab.Controller).ToString();
                ulTag.InnerHtml += liTag.ToString();
            }
            return MvcHtmlString.Create(ulTag.ToString());
            
        }
    }
}